<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/10/25
  Time: 16:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">


        <div class="layui-card-body">
            <table id="contentCategoryManage" lay-filter="contentCategoryManage"></table>
            <script type="text/html" id="optionToolbar">
                <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="add">新增  </button>
                        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="dels"id="dels">批量删除</button>

                </div>
            </script>
            <script type="text/html" id="optionBar">
                {{#  if(d.type==null ){ }}
                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="pid">下级</a>

                {{#  } else { }}
                <a class="layui-btn  layui-btn-xs" lay-event="pidUp">上级</a>

                {{#  } }}
                {{#  if(d.type!=null ){ }}
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                {{#  } }}
            </script>
            <script type="text/html" id="gmtModifiedTpl">
                {{#
                var date = new Date();
                date.setTime(d.gmtModified);
                return date.Format("yyyy-MM-dd hh:mm:ss");
                }}
            </script>

            <script type="text/html" id="isDisabledTpl">
                <input type="checkbox" name="state" value="{{d.id}}" title="禁用" lay-filter="isDisabledFilter" {{
                       d.state== 1 ? 'checked' : '' }}>
            </script>
            <script type="text/html" id="photo">

                <div><img src="{{d.photo==null?'<%=basePath%>resources/images/noImage.jpg':d.photo}}" style="height: 28px" class="layui-table-link"></div>
            </script>
        </div>
    </div>
</div>

<%@include file="../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function (){
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        table.render({
            elem: '#contentCategoryManage',
            url: '<%=basePath%>manager/content/category/list.action',
            toolbar: '#optionToolbar',
            cols: [[
                {type: 'checkbox',fixed:'left'}
                ,{field: 'id', width: 50, title: 'ID', sort: true}
                , {field: 'name', title: '名称'}
                , {title: '更新时间', sort: true, templet: "#gmtModifiedTpl"}
                , {title: "操作", width: 200, align: "center", fixed: "right", toolbar: "#optionBar"}

            ]],
            page: !0,
            limit: 10,
            height: "full-130",
            text: {none:"暂无可显示数据"},
            response: {
                statusCode: 200
            }
        });

        table.on('toolbar(contentCategoryManage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    var dialog=new UtilClass.LayerDialog({
                        title:"添加组",
                        content:"<%=basePath%>manager/content/category/create.action"
                    });
                    dialog.layerShow();
                    <%--layer.open({--%>
                        <%--type: 2--%>
                        <%--,title: '添加新闻'--%>
                        <%--,content: '<%=basePath%>manager/content/category/create.action'--%>
                        <%--,maxmin: true--%>
                        <%--,area: ['100%', '100%']--%>
                        <%--,btn: ['确定', '取消']--%>
                        <%--,yes: function(index, layero){--%>
                            <%--var iframeWindow = window['layui-layer-iframe'+ index];--%>
                            <%--var submitID = 'LAY-submit';--%>
                            <%--var submit = layero.find('iframe').contents().find('#'+ submitID);--%>
                            <%--//监听提交--%>
                            <%--iframeWindow.layui.form.on('submit('+ submitID +')', function(data){--%>
                                <%--var jsonData=window[layero.find('iframe')[0]['name']].getAllEdit();--%>
                                <%--var formData = data.field;--%>
                                <%--var allNews=[];--%>
                                <%--for(var i=0;i<jsonData.length;i++){--%>
                                    <%--var category={};--%>
                                    <%--category['title']=formData[jsonData[i]['code']+'Title'];--%>
                                    <%--category['new']=formData['new'];--%>
                                    <%--category['photo']=formData['photo'];--%>
                                    <%--category['description']=formData[jsonData[i]['code']+'Desc'];--%>
                                    <%--category['isPublic']=formData['isPublic'];--%>
                                    <%--category['content']=jsonData[i]['content'];--%>
                                    <%--category['keyword']=formData[jsonData[i]['code']+'Keyword'];--%>
                                    <%--category['language'] = jsonData[i]['code'];--%>
                                    <%--category['type']=formData['type'];--%>
                                    <%--category['attachment']=formData['attachment'];--%>
                                    <%--allNews.push(category);--%>
                                <%--}--%>
                                <%--allNews=JSON.stringify(allNews)--%>
                                <%--layer.load(2);--%>
                                <%--$.ajax({--%>
                                    <%--url:"<%=basePath%>manager/content/category/create.action",--%>
                                    <%--type:"POST",--%>
                                    <%--data:{"contentNewses":allNews},--%>
                                    <%--dataType:"JSON",--%>
                                    <%--success:function (data) {--%>
                                        <%--layer.closeAll('loading');--%>
                                        <%--if(data.flag){--%>
                                            <%--layer.msg("添加成功");--%>
                                            <%--table.reload('contentCategoryManage');--%>
                                            <%--layer.close(index);--%>
                                        <%--}else{--%>
                                            <%--layer.msg(data.msg);--%>
                                        <%--}--%>
                                    <%--}--%>
                                <%--});--%>
                            <%--});--%>
                            <%--submit.trigger('click');--%>
                        <%--}--%>
                    <%--});--%>
                    break;

                case 'dels':
                    var data = checkStatus.data;

                    var List=JSON.stringify(data);
                    var jsList =JSON.parse(List);
                    if(jsList[0]==null){
                        layer.msg('请选中至少一行');

                    }else{


                        var chars=new Array();
                        for(var  li in jsList){
                            chars[li]=jsList[li].id;
                        }
                        var str="";
                        for( var i=0;i<chars.length;i++){
                            if(i==chars.length-1){
                                str+=chars[i];
                            }
                            else{str=str+chars[i]+",";}

                        }
                        layer.load(2);
                        $.ajax({
                            type: "get",
                            url: "<%=basePath%>manager/content/category/delete/"+str+".action",
                            success: function(data) {
                                layer.closeAll("loading");
                                data=JSON.parse(data);


                                if(data.flag){
                                    layer.msg("删除成功");
                                    table.reload('contentCategoryManage');

                                }else{
                                    layer.msg(data.msg, {icon: 5});
                                }
                            }
                        });
                        break;}
            };
        });
        table.on("tool(contentCategoryManage)", function (e){
            if ("del" === e.event){
                layer.confirm("真的删除行么", function (t) {
                    layer.close(t);
                    var List=JSON.stringify(e.data);
                    var jsList =JSON.parse(List);
                    var ids=jsList.id;
                    layer.load(2);
                    $.ajax({
                        type: "get",
                        url: "<%=basePath%>manager/content/category/delete/"+ids+".action",
                        success: function(data) {
                            layer.closeAll("loading");
                            data=JSON.parse(data);


                            if(data.flag){
                                table.reload('contentCategoryManage');

                            }else{
                                layer.msg(data.msg, {icon: 5});
                            }
                        }
                    });

                })
            }else if ("edit" === e.event) {
                $(e.tr);
                var dialog=new UtilClass.LayerDialog({
                    title:"编辑["+e.data.name+"]",
                    content:"<%=basePath%>manager/content/category/update/"+e.data.id+".action"
                });
                dialog.layerShow();
                <%--layer.open({--%>
                    <%--type: 2,--%>
                    <%--title: "编辑["+e.data.title+"]",--%>
                    <%--content: "<%=basePath%>manager/content/category/update/"+e.data.group+".action",--%>
                    <%--maxmin: !0,--%>
                    <%--area: ["100%", "100%"],--%>
                    <%--btn: ["确定", "取消"],--%>
                    <%--yes: function (index, layero) {--%>
                        <%--var iframeWindow = window['layui-layer-iframe'+ index];--%>
                        <%--var submitID = 'LAY-submit'--%>
                        <%--var submit = layero.find('iframe').contents().find('#'+ submitID);--%>
                        <%--iframeWindow.layui.form.on("submit(" + submitID + ")", function (data) {--%>
                            <%--var jsonData=window[layero.find('iframe')[0]['name']].getAllEdit();--%>
                            <%--var formData = data.field;--%>
                            <%--var allNews=[];--%>
                            <%--for(var i=0;i<jsonData.length;i++){--%>
                                <%--var category={};--%>
                                <%--category['title']=formData[jsonData[i]['code']+'Title'];--%>
                                <%--category['new']=formData['new'];--%>
                                <%--category['photo']=formData['photo'];--%>
                                <%--category['description']=formData[jsonData[i]['code']+'Desc'];--%>
                                <%--category['isPublic']=formData['isPublic'];--%>
                                <%--category['content']=jsonData[i]['content'];--%>
                                <%--category['keyword']=formData[jsonData[i]['code']+'Keyword'];--%>
                                <%--category['language'] = jsonData[i]['code'];--%>
                                <%--category['type']=formData['type'];--%>
                                <%--category['attachment']=formData['attachment'];--%>
                                <%--allNews.push(category);--%>
                            <%--}--%>
                            <%--allNews=JSON.stringify(allNews)--%>
                            <%--layer.load(2);--%>
                            <%--$.ajax({--%>
                                <%--url:"<%=basePath%>manager/content/category/update/"+formData.id+".action",--%>
                                <%--type:"POST",--%>
                                <%--data:{"contentNewses":allNews},--%>
                                <%--dataType:"JSON",--%>
                                <%--success:function (data) {--%>
                                    <%--layer.closeAll('loading');--%>
                                    <%--if(data.flag){--%>
                                        <%--table.reload('contentCategoryManage');--%>
                                        <%--layer.close(index);--%>
                                    <%--}else{--%>
                                        <%--layer.msg(data.msg, {icon: 5});--%>
                                    <%--}--%>
                                <%--}--%>
                            <%--});--%>
                        <%--});--%>
                        <%--submit.trigger("click")--%>
                    <%--},--%>
                    <%--success: function (e, t) {--%>

                    <%--}--%>
                <%--})--%>
            }else if ("pid" === e.event){
                table.reload('contentCategoryManage', {
                    where: {id:e.data.id}
                });
            }else if ("pidUp" === e.event){
                table.reload('contentCategoryManage', {
                    where: {id:null}
                });
            }
        });

        //监听搜索
        form.on('submit(Type-serch)', function (data) {
            var field = data.field;
            $(".layui-laypage-skip").find("input").val("1");
            $(".layui-laypage-btn").click();

            table.reload('contentCategoryManage', {
                where: {name:field.name,language:field.language}
            });
        });


    });
    function edit(e) {

    }

</script>
</body>
</html>

